package org.softmed.rest.admin.file;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import org.softmed.swing.IconManager;

public class ActionPanel extends JPanel implements ActionListener {

	JButton createDir = new JButton(IconManager.newFolder);
	JButton createFile = new JButton(IconManager.newDocument);
	JButton openFile = new JButton(IconManager.openDocument);
	JButton copy = new JButton(IconManager.copy);
	JButton paste = new JButton(IconManager.paste);
	JButton delete = new JButton(IconManager.remove);

	int width = 30;
	int height = 30;

	public ActionPanel() {
		setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
		setBackground(Color.PINK);
		// setLayout(new GridLayout(1,6));
		setMaximumSize(new Dimension(300, height));
		setMinimumSize(new Dimension(300, height));
		setPreferredSize(new Dimension(300, height));

		addButton(createDir);
		addButton(createFile);
		addButton(openFile);
		addButton(copy);
		addButton(paste);
		addButton(delete);
		add(new JLabel("WTF"));

	}

	protected void addButton(JButton button) {
		button.setPreferredSize(new Dimension(width, height));
		button.setMaximumSize(new Dimension(width, height));
		button.setMinimumSize(new Dimension(width, height));
		button.addActionListener(this);
		button.setEnabled(false);
		add(button);
	}

	public void enableDirectoryFunctions() {
		setButtonsEnabled(false);
		createDir.setEnabled(true);
		createFile.setEnabled(true);
		copy.setEnabled(true);
		delete.setEnabled(true);
	}

	public void enableFileFunctions() {
		setButtonsEnabled(false);
		openFile.setEnabled(true);
		copy.setEnabled(true);
		delete.setEnabled(true);
	}

	public void setButtonsEnabled(boolean enabled) {
		createDir.setEnabled(enabled);
		createFile.setEnabled(enabled);
		openFile.setEnabled(enabled);
		copy.setEnabled(enabled);
		paste.setEnabled(enabled);
		delete.setEnabled(enabled);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {

		Object source = arg0.getSource();

		if (source == delete) {

			int duh = JOptionPane
					.showConfirmDialog(
							this,
							"Are you sure you want to delete this ? \nAll contents will be lost !",
							"Warning", JOptionPane.YES_NO_OPTION,
							JOptionPane.QUESTION_MESSAGE);

			if (duh == JOptionPane.YES_OPTION) {

			} else {

			}

			return;

		}
	}

	// }

	public JButton getCreateDir() {
		return createDir;
	}

	public JButton getCreateFile() {
		return createFile;
	}

	public JButton getOpenFile() {
		return openFile;
	}

	public JButton getCopy() {
		return copy;
	}

	public JButton getPaste() {
		return paste;
	}

	public JButton getDelete() {
		return delete;
	}

	public int getWidth() {
		return width;
	}

	public int getHeight() {
		return height;
	}

}
